package com.jlf.tool.validation;


import com.jlf.tool.validation.constraint.FieldCompareValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

/**
 * 字段比较
 *
 * @author wujr
 * 2022/8/15
 * @version 1.0
 * 【变更历史】
 * [wujr 2022/8/15 1.0 新增]
 */

@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE,
        ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = FieldCompareValidator.class)
@Documented
@Repeatable(FieldCompare.List.class)
public @interface FieldCompare {
    String beginField();

    String endField();

    String message() default "开始值不能大于结束值";

    /**
     * 比较是否包括二者相等
     * @return 默认为false，表示不能相等
     */
    boolean includeEqual() default false;

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
            ElementType.ANNOTATION_TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @interface List {
        FieldCompare[] value();
    }
}
